package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.SpokenTeacherTag;
import com.ruoyi.system.mapper.SpokenTeacherTagMapper;
import com.ruoyi.system.service.ISpokenTeacherService;
import com.ruoyi.system.service.ISpokenTeacherTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpokenTeacherTagImpl implements ISpokenTeacherTagService {

    @Autowired
    SpokenTeacherTagMapper teacherTagMapper;

    @Autowired
    ISpokenTeacherService teacherService;

    @Override
    public int insert(SpokenTeacherTag tag) {
        return teacherTagMapper.insert(tag);
    }

    @Override
    public List<SpokenTeacherTag> selectList(SpokenTeacherTag tag) {
        return teacherTagMapper.selectList(tag);
    }

    @Override
    public SpokenTeacherTag selectById(Long tagId) {
        return teacherTagMapper.selectById(tagId);
    }

    @Override
    public int update(SpokenTeacherTag tag) {
        return teacherTagMapper.update(tag);
    }

    @Override
    public int delete(Long tagId) {
        // 查询当前分类是否被教师关联
        int count = teacherService.selectCountByTagId(tagId);
        if(count > 0){
            throw new ServiceException("当前分类已被教师关联，无法删除！");
        }
        return teacherTagMapper.delete(tagId);
    }
}
